package mysql

import (
	"database/sql"
	"web_app/models"
)

//社区分类列表查询
func GetCommunityList() (communityList []*models.Community, err error) {
	sqlStr := "select community_id,community_name from community"
	err = db.Select(&communityList, sqlStr)
	if err != nil {
		if err == sql.ErrNoRows {
			err = nil
		}
	}
	return
}

func GetCommunityDetailByID(id int64) (data *models.CommunityDetail, err error) {
	sqlStr := "select community_id,community_name,introduction,create_time from community where community_id=?"
	data = new(models.CommunityDetail)
	err = db.Get(data, sqlStr, id)
	if err != nil {
		if err == sql.ErrNoRows {
			err = ErrInvalidID
		}
	}
	return
}
